home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  2.4 KB  |  78 lines

  1. /*
  2. //   (C) COPYRIGHT International Business Machines Corp. 1993
  3. //   All Rights Reserved
  4. //   Licensed Materials - Property of IBM
  5. //   US Government Users Restricted Rights - Use, duplication or
  6. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. //
  8.  
  9. //
  10. // Permission to use, copy, modify, and distribute this software and its
  11. // documentation for any purpose and without fee is hereby granted, provided
  12. // that the above copyright notice appear in all copies and that both that
  13. // copyright notice and this permission notice appear in supporting
  14. // documentation, and that the name of I.B.M. not be used in advertising
  15. // or publicity pertaining to distribution of the software without specific,
  16. // written prior permission. I.B.M. makes no representations about the
  17. // suitability of this software for any purpose.  It is provided "as is"
  18. // without express or implied warranty.
  19. //
  20. // I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  22. // BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. // Author:  John Spitzer, IBM AWS Graphics Systems (Austin)
  28. //
  29. */
  30.  
  31. #include "Timer.h"
  32. #include "Global.h"
  33. #include <stdlib.h>
  34. #include <malloc.h>
  35.  
  36. TimerPtr new_Timer()
  37. {
  38.     TimerPtr this = (TimerPtr)malloc(sizeof(Timer));
  39.     CheckMalloc(this);
  40.     this->elapsed = 0.0;
  41.     return this;
  42. }
  43.  
  44. void delete_Timer(TimerPtr this)
  45. {
  46.     free(this);
  47. }
  48.  
  49. void Timer__Start(TimerPtr this)
  50. {
  51. #if defined( WIN32)
  52.     this->start = GetTickCount();
  53. #elif defined( __OS2__)
  54.     DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &this->start, sizeof( this->start));
  55. #else
  56.     this->start = times(&this->buf);
  57. #endif
  58. }
  59.  
  60. void Timer__Stop(TimerPtr this)
  61. {
  62. #if defined( WIN32)
  63.     this->stop = GetTickCount();
  64.     this->elapsed = ((float)(this->stop) - (float)(this->start)) / 1000.0F;
  65. #elif defined( __OS2__)
  66.     DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &this->stop, sizeof( this->stop));
  67.     this->elapsed = (( float)( this->stop - this->start)) / 1000.0F;
  68. #else
  69.     this->stop = times(&this->buf);
  70.     this->elapsed = (float)(this->stop - this->start)/(float)CLK_TCK;
  71. #endif
  72. }
  73.  
  74. float Timer__Read(TimerPtr this)
  75. {
  76.     return this->elapsed;
  77. }
  78.